{
  "cells": [
  {
   "cell_type": "markdown",
   "id": "51b3b00e",
   "metadata": {},
   "source": [
    "# Count primes below a given bound"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "83062572",
   "metadata": {},
   "outputs": [],
   "source": [
    "import taichi as ti\n",
    "\n",
    "def test_kernel_print():\n",
    "    N = 10000\n",
    "    ti.init()\n",
    "    @ti.func\n",
    "    def is_prime(n: int):\n",
    "        result = True\n",
    "        for k in range(2, int(n**0.5) + 1):\n",
    "            if n % k == 0:\n",
    "                result = False\n",
    "                break\n",
    "        return result\n",
    "\n",
    "    @ti.kernel\n",
    "    def count_primes(n: int) -> int:\n",
    "        count = 0\n",
    "        for k in range(2, n):\n",
    "            if is_prime(k):\n",
    "                count += 1\n",
    "\n",
    "        return count\n",
    "\n",
    "    count_primes(N)\n",
    "    \n",
    "test_kernel_print()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
